#{extends 'common/base.html' /}
 <script>
 $(function(){
	 var sb = new StringBuffer();
	
	 $("#addGourp").click(function(){
		 var flag = true;
		 $("input[name='gourp_name']").each(function(){
			 if($(this).val()==''){
				alert("请保存之后再进行添加!");
				flag =  false;
			 };
		 });
		 if(flag){
		 sb.append($("#gourpData").html());
		 sb.append("<tr><td><input type='checkbox' /></td><td></td><td><input type='text' class='am-input-sm' id='gourp_name' name='gourp_name'></td><td></td><td>"+
				 "<button  class='am-btn am-btn-default am-btn-xs am-text-secondary' id='save_add' onclick='saveAdd();'><span class='am-icon-pencil-square-o'></span>保存</button></td></tr>");
		 $("#gourpData").html(sb.toString());
		 }
	 });
	 
	 
 });
 function editGourpInit(gourp_id){
     var rows=document.getElementById("gourpData").rows;  
     for(var i=0;i<rows.length;i++){  
         (function(i){  
           var temp=rows[i].cells[1];
           if($(temp).html()==gourp_id){
				$(rows[i].cells[2]).html("<input type='text' class='am-input-sm' id='gourp_name_edit' name='gourp_name' value='	"+$(rows[i].cells[2]).html()+"'>")
				$(rows[i].cells[4]).html(	 "<button  class='am-btn am-btn-default am-btn-xs am-text-secondary' onclick='editGourp(\""+$(temp).html()+"\")'><span class='am-icon-pencil-square-o'></span>保存</button>")
           }
           var obj=rows[i];  
           })(i)  
       }  
     
 }
 function editGourp(gourp_id){
	 var gourp_name = $("#gourp_name_edit").val();
	 	if(gourp_name==''){
	 		alert("请填写组名称");
	 		return false;
	 	}
	 	$.post("editGourp","gourp_name="+gourp_name+"&gourp_id="+gourp_id,function(data){
	 		 alert(data.msg);
	 			location.reload();
		
	 	});
	 
 }
 function delGourp(gourp_id){
	 if(confirm("确认删除吗?")){
		 $.post("delGourp","gourp_id="+gourp_id,function(data){
	 		 alert(data.msg);
	 			location.reload();
		
	 	});
		 
	 }
 }
 function saveAdd(){
	 var gourp_name = $("#gourp_name").val();
	 	if(gourp_name==''){
	 		alert("请填写组名称");
	 		return false;
	 	}
	 	$.post("addGourp","gourp_name="+gourp_name,function(data){
	 		 alert(data.msg);
	 			location.reload();
		
	 	});
	 
 }
 
 </script>
<!-- content start -->
<div class="admin-content">
	<div class="am-cf am-padding">
		<div class="am-fl am-cf">
			<strong class="am-text-primary am-text-lg">组管理</strong> / <small>Gourp</small>
		</div>
	</div>
    <div class="am-g">
      <div class="am-u-sm-12 am-u-md-6">
        <div class="am-btn-toolbar">
          <div class="am-btn-group am-btn-group-xs">
            <button type="button" class="am-btn am-btn-default" id="addGourp"><span class="am-icon-plus"></span> 新增</button>
          	<!-- 
            <button type="button" class="am-btn am-btn-default"><span class="am-icon-save"></span> 保存</button>
            <button type="button" class="am-btn am-btn-default"><span class="am-icon-archive"></span> 审核</button>
            <button type="button" class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除</button>
          	 -->
          </div>
        </div>
      </div>
      </div>
	<div class="am-g">
		<div class="am-u-sm-12">
			<table id="mytable" class="am-table am-table-striped am-table-hover table-main">
				<thead>
					<tr>
						<th class="table-check"><input type="checkbox" /></th>
						<th class="table-type">组id</th>
						<th class="table-type">组名</th>
						<th class="table-title">创建时间</th>
						<th  class="table-set">操作</th>
					</tr>
				</thead>
				<tbody id="gourpData">
					#{if json!=null} #{set count:1/} #{list
					items:json.data.data,as:'bean'}
					<tr>
						<td><input type="checkbox" /></td>
						<td>${bean?.gourp_id}</td>
						<td>${bean?.gourp_name}</td>
						<td>${bean?.create_time}</td>
						<td>
						 <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
						   	   <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 工序</button>
						   	   <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 操作员</button>
							   <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="editGourpInit('${bean?.gourp_id}')"><span class="am-icon-pencil-square-o"></span> 编辑</button>
								<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="delGourp('${bean?.gourp_id}')"><span class="am-icon-trash-o"></span> 删除</button>
								</div>
								</div>
								
						</td>
					</tr>
					#{/list} #{/if}
				</tbody>
			</table>
		</div>
		
	</div>
 
 </div>
<!-- content end -->